<?php

require_once dirname(__FILE__).'/../bootstrap/unit.php';
 
$t = new lime_test(19, new lime_output_color());

$fn = '::isValidNote()';
$t->comment($fn);
$t->ok(Zenino_Note_Toolkit::isValidNote('D##'), $fn.'returns true for D##');
$t->ok(Zenino_Note_Toolkit::isValidNote('F'), $fn.'returns true for F');
$t->ok(!Zenino_Note_Toolkit::isValidNote('H'), $fn.'returns false for H');

$fn = '::getAccidentals()';
$t->comment($fn);
$t->is(Zenino_Note_Toolkit::getAccidentals('D##'), array('#','#'), $fn.' extracts accidentals from note');
$t->is(Zenino_Note_Toolkit::getAccidentals('F'), array(), $fn.' returns empty array if no accidentals');

$fn = '::intToNote()';
$t->comment($fn);
$t->is(Zenino_Note_Toolkit::intToNote(0), 'C', $fn.' converts integer 0 to note C');
try
{
  Zenino_Note_Toolkit::intToNote(12);
  $t->fail('no code should be executed after throwing an exception');
}
catch (RangeError $e)
{
  $t->pass($fn.' throws a RangeError exception when $int is not between 0-11');
}

$fn = '::noteToInt()';
$t->comment($fn);
$t->is(Zenino_Note_Toolkit::noteToInt('Db'), 1, $fn.' converts note Db to integer 1');
$t->is(Zenino_Note_Toolkit::noteToInt('C##'), 2, $fn.' converts note C## to integer 2');
$t->is(Zenino_Note_Toolkit::noteToInt('F###'), 8, $fn.' converts note F### to integer 8');
try
{
  Zenino_Note_Toolkit::noteToInt('foo');
  $t->fail('no code should be executed after throwing an exception');
}
catch (NoteFormatError $e)
{
  $t->pass($fn.' throws a NoteFormatError exception when note is not well formated');
}

$fn = '::isEnharmonic()';
$t->comment($fn);
$t->ok(Zenino_Note_Toolkit::isEnharmonic('Db', 'C#'), $fn.' returns true for Db and C#');
$t->ok(!Zenino_Note_Toolkit::isEnharmonic('Db', 'C##'), $fn.' returns false for Db and C##');

$fn = '::removeRedundantAccidentals()';
$t->comment($fn);
$t->is(Zenino_Note_Toolkit::removeRedundantAccidentals('C##b'), 'C#', $fn.' transforms C##b to C#');
$t->is(Zenino_Note_Toolkit::removeRedundantAccidentals('Eb##b'), 'E', $fn.' transforms Eb##b to E');

$fn = '::augment()';
$t->comment($fn);
$t->is(Zenino_Note_Toolkit::augment('Dbb'), 'Db', $fn.' transforms Dbb to Db');
$t->is(Zenino_Note_Toolkit::augment('C#'), 'C##', $fn.' transforms C# to C##');

$fn = '::diminish()';
$t->comment($fn);
$t->is(Zenino_Note_Toolkit::diminish('Dbb'), 'Dbbb', $fn.' transforms Dbb to Dbbb');
$t->is(Zenino_Note_Toolkit::diminish('C#'), 'C', $fn.' transforms C# to C');